In order to work with the Standard Sound Component, it is necessary to open a connection to the component using the Component Manager. An example of how to do this is shown in Listing 23-1 .
Listing 1 Opening a connection to the Standard Sound Component
ComponentInstance ci;
ci = OpenDefaultComponent(StandardCompressionType,
StandardCompressionSubTypeSound);
After obtaining a connection to the Standard Sound Component, it may be appropriate to configure the dialog to present a reasonable set of values. This is done with SCSetInfo as shown in Listing 23-2 . This example sets the sample rate to 32000 Hz, the sample size to 8 bits, the channel count to 1, and the compression format to MACE 6:1. If SCSetInfo is not called for a given parameter, that parameter will default to an appropriate value.
Listing 2 Setting initial values for the dialog
UnsignedFixed rate;
short sSize, cCount;
OSType compType;
rate = FixRatio(32000, 1);
SCSetInfo(ci, scSoundSampleRateType, &rate);
sSize = 8;
SCSetInfo(ci, scSoundSampleSizeType, &sSize);
cCount = 1;
SCSetInfo(ci, scSoundChannelCountType, &cCount);
compType = kMACE6Compression;
SCSetInfo(ci, scSoundCompressionType, &compType);
It is sometimes necessary to restrict the list of compression types appearing in the compression menu. For example, some clients may not support generation of compressed data. The Standard Sound Component allows the client to provide a list of compression types that should be displayed. In the following example in Listing 23-3 , all compression types except for uncompressed are eliminated from the list.
Listing 3 Restricting the list of compression types
Handle compressionTypeList;
compressionTypeList = NewHandle(sizeof(OSType));
**(OSType **)compressionTypeList = kRawCodecType;
SCSetInfo(ci, scCompressionListType, &compressionTypeList);
To display the dialog, use SCRequestImageSettings as shown in Listing 23-4 . If the user cancels the dialog, userCanceledErr is returned.
Listing 4 Displaying the dialog
OSErr err;
err = SCRequestImageSettings(ci);
After the dialog has been displayed, the settings can be retrieved using the SCGetInfo call with the appropriate selectors. The example in Listing 23-5 shows how to retrieve the selected sample rate, sample size, compression format, and number of channels.
Listing 5 Retrieving settings from the dialog
UnsignedFixed rate;
short sSize, cCount;
OSType compType;
SCGetInfo(ci, scSoundSampleRateType, &rate);
SCGetInfo(ci, scSoundSampleSizeType, &sSize);
SCGetInfo(ci, scSoundChannelCountType, &cCount);
SCGetInfo(ci, scSoundCompressionType, &compType);
It is also possible to retrieve all of the current settings in a single Handle, as shown in the next example. This can be convenient when saving user settings.
Handle h;
SCGetInfo(ci, scSettingsStateType, &h);
Once the settings have been retrieved in the handle, they can be restored using SCSetInfo as show as follows.
SCSetInfo(ci, scSettingsStateType, &h);
When you are finished with the Standard Sound Component, close the connection to the component as shown as follows.
CloseComponent(ci);
The following constants have been added to the list of selectors that can be passed to SCGetInfo and SCSetInfo . These selectors are only supported by the Standard Sound Dialog, not the Standard Compression Dialog.
The Standard Sound Component also supports the following selectors.
The Standard Sound Component implements the following functions from the Standard Compression Component interface. For more details, see the Standard Compression Component chapter of Inside Macintosh: QuickTime Components .